<?php

/**
 * ECSHOP 商品分类
 * ============================================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: category.php 17217 2011-01-19 06:29:08Z liubo $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}


//-- PROCESSOR
/*------------------------------------------------------ */

/* 页面的缓存ID */
$cache_id = sprintf('%X', crc32($cat_id));

if (!$smarty->is_cached('compose.dwt', $cache_id))
{
    assign_template('c', array($cat_id));
    $position = assign_ur_here($cat_id, $brand_name);
    $smarty->assign('page_title',       $position['title']);    // 页面标题
    $smarty->assign('show_marketprice', $_CFG['show_marketprice']);
    $smarty->assign('filter_attr',      $filter_attr_str);
    $smarty->assign('feed_url',         ($_CFG['rewrite'] == 1) ? "feed-c$cat_id.xml" : 'feed.php?cat=' . $cat_id); // RSS URL
    // 商品列表
}
    $goods_list = category_get_goods(101, "10000", "1");
    

    $ad_1=get_ad(9);//分类顶部广告

    $goods_list=array_values($goods_list);
    foreach ($goods_list as $key => $value) {
        $goods_list[$key]['goods_thumb']=$ad_1[$key]['ad_code'];
    }
    
    $smarty->assign('goods_list', $goods_list);
    $smarty->assign('top_title', $_LANG['compose']);
    $smarty->assign('footer', get_footer());
    $smarty->display('compose.dwt', $cache_id);




















function category_get_goods($children, $size, $page=1)
{   
    
    /* 获得商品列表 */
   
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
        "g.is_delete = 0   AND g.cat_id =  ".$children;
    // 检测排序类型跟方式
   
    $sql = 'SELECT g.*  ' .
    'FROM ' . $GLOBALS['ecs']->table('goods') . ' g ' .
     "WHERE $where ORDER BY g.sort_order ASC";
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
    // 重组输出数组
    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res))
    {  
            // 判断是否在限时特购是的话显示优惠价
        if($row['promote_price']>0 && $row['promote_end_date'] > time()){
            $row['shop_price'] = $row['promote_price'];
        }
        $arr[$row['goods_id']]['goods_id']         = $row['goods_id'];
        $arr[$row['goods_id']]['name']             = $row['goods_name'];
        $arr[$row['goods_id']]['click_count']      = $row['click_count'];
        /* 市场价 */
        if($row['market_price'] > 0){//存在市场价时的市场价
            $arr[$row['goods_id']]['market_price'] = price_format($row['shop_price']);
        }else{//不存在市场价时的市场价
            $arr[$row['goods_id']]['market_price'] = price_format(sprintf('%.1f',$row['shop_price']*1.2));
        }
        $arr[$row['goods_id']]['shop_price']       = price_format($row['shop_price']);
        $arr[$row['goods_id']]['goods_thumb']      = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['url']              = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);

    }
    return $arr;
}

/**
 * 获得广告位
 *
 * @access  private
 * @return  array
 */
    
    function get_ad($position_id = 0){
        if(!$position_id) return false;
        $position_id = intval($position_id);
        $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('ad') . " WHERE position_id = '$position_id' ORDER BY ad_name ASC ";
        return $GLOBALS['db']->getAll($sql);
    }









?>
